<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>09.VueComponent</title>
    <!-- 引入Vue -->
    <script type="text/javascript" src="../../js/vue.js"></script>
  </head>
  <body>
    <!-- 准备好一个容器-->
    <div id="demo"></div>

    <script type="text/javascript">

      const Student = Vue.extend({
        name:'Student',
        template:`
          <div>
            <h1>我是Student组件</h1>
            <h3>姓名：{{name}}</h3>  
            <h3>年龄：{{age}}</h3>  
            <button @click="showInfo">点我查看信息</button>
            <button @click="age++">年龄+1</button>
          </div>
        `,
        data(){
          return {
            name:'tony',
            age:19
          }
        },
        methods:{
          showInfo(){
            console.log('@',this)
            // alert(`名字：${this.name}，年龄：${this.age}`)
          }
        }
      })
      
      const Person = Vue.extend({
        name:'Person',
        template:`
          <div>
            <h1>人员信息</h1>
            <h3>姓名：{{pname}}</h3>
            <h3>年龄：{{age}}</h3>
            <button @click="showPerson">点我提示个人信息</button>  
          </div>
        `,
        data(){
          return {
            pname:'强哥',
            age:18,
          }
        },
        methods:{
          showPerson(){
            alert(`我叫${this.pname}我今天${this.age}岁了`)
          }
        }
      })
      
      // console.log('!!!',Student)
      // console.log('???',Person)

      new Vue({
        el:'#demo',
        template:`
          <div>
            <Student/>  
            <Student/>  
          </div>
        `,
        components:{Student}
      })

    </script>
  </body>
</html>